﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PmuRegistry.Silverlight.Utilities;
using System.Windows.Media.Animation;

namespace PmuRegistry.Silverlight.ModalDialogs
{
	public partial class SystemMessages : ChildWindow
	{
		Message m_systemMessage = new Message();
		public SystemMessages(Message message, ButtonType buttonType)
		{
			InitializeComponent();
			m_systemMessage = message;
			Loaded += new RoutedEventHandler(SystemMessages_Loaded);
			ButtonOk.Click += new RoutedEventHandler(ButtonOk_Click);
			ButtonYes.Click += new RoutedEventHandler(ButtonYes_Click);
			ButtonNo.Click += new RoutedEventHandler(ButtonNo_Click);
			ButtonCancel.Click += new RoutedEventHandler(ButtonCancel_Click);
			if (message.UserMessageType == MessageType.Success)
			{
				this.Title = "NASPI PMU Registry: Operation Completed Successfully!";
				TextBlockMessageType.Text = "SUCCESS";
				ImageMessageType.Source = new BitmapImage(new Uri(@"../Images/Success.png", UriKind.Relative));
				BorderMain.Background = Application.Current.Resources["GreenRadialGradientBrush"] as Brush;
			}
			else if (message.UserMessageType == MessageType.Warning)
			{
				this.Title = "NASPI PMU Registry: Warning!";
				TextBlockMessageType.Text = "WARNING";
				ImageMessageType.Source = new BitmapImage(new Uri(@"../Images/Warning.png", UriKind.Relative));
				BorderMain.Background = Application.Current.Resources["YellowRadialGradientBrush"] as Brush;
			}
			else if (message.UserMessageType == MessageType.Error)
			{
				this.Title = "NASPI PMU Registry: Error Occured!";
				TextBlockMessageType.Text = "ERROR";
				ImageMessageType.Source = new BitmapImage(new Uri(@"../Images/Error.png", UriKind.Relative));
				BorderMain.Background = Application.Current.Resources["RedRadialGradientBrush"] as Brush;
			}
			else //treat as information.
			{
				this.Title = "NASPI PMU Registry: Information Only!";
				TextBlockMessageType.Text = "INFORMATION";
				ImageMessageType.Source = new BitmapImage(new Uri(@"../Images/Information.png", UriKind.Relative));
				BorderMain.Background = Application.Current.Resources["BlueRadialGradientBrush"] as Brush;
			}

			if (buttonType == ButtonType.OkOnly)
			{
				ButtonOk.Visibility = Visibility.Visible;
				ButtonCancel.Visibility = Visibility.Collapsed;
				ButtonYes.Visibility = Visibility.Collapsed;
				ButtonNo.Visibility = Visibility.Collapsed;
			}
			else if (buttonType == ButtonType.OkCancel)
			{
				ButtonOk.Visibility = Visibility.Visible;
				ButtonCancel.Visibility = Visibility.Visible;
				ButtonYes.Visibility = Visibility.Collapsed;
				ButtonNo.Visibility = Visibility.Collapsed;
			}
			else if (buttonType == ButtonType.YesNo)
			{
				ButtonOk.Visibility = Visibility.Collapsed;
				ButtonCancel.Visibility = Visibility.Collapsed;
				ButtonYes.Visibility = Visibility.Visible;
				ButtonNo.Visibility = Visibility.Visible;
			}
			else if (buttonType == ButtonType.YesNoCancel)
			{
				ButtonOk.Visibility = Visibility.Collapsed;
				ButtonCancel.Visibility = Visibility.Visible;
				ButtonYes.Visibility = Visibility.Visible;
				ButtonNo.Visibility = Visibility.Visible;
			}

		}

		void ButtonCancel_Click(object sender, RoutedEventArgs e)
		{
			//Storyboard sb = new Storyboard(); 
			//sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
			//Storyboard.SetTarget(sb, ButtonCancelTransform);
			//sb.Begin();
		}

		void ButtonNo_Click(object sender, RoutedEventArgs e)
		{
			//Storyboard sb = new Storyboard(); 
			//sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
			//Storyboard.SetTarget(sb, ButtonNoTransform);
			//sb.Begin();
		}

		void ButtonYes_Click(object sender, RoutedEventArgs e)
		{
			//Storyboard sb = new Storyboard(); 
			//sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
			//Storyboard.SetTarget(sb, ButtonYesTransform);
			//sb.Begin();
		}

		void ButtonOk_Click(object sender, RoutedEventArgs e)
		{
			//Storyboard sb = new Storyboard(); 
			//sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
			//Storyboard.SetTarget(sb, ButtonOkTransform);
			//sb.Begin();
			this.DialogResult = true;
		}

		void SystemMessages_Loaded(object sender, RoutedEventArgs e)
		{
			GridSystemMessageDetail.DataContext = m_systemMessage;
		}
		
	}
}

